package org.trade.user.server;

import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.trade.common.constant.TradeEnums;

/**
 * rest风格来提供调用的 配置jetty-all作为服务的提供方
 */
public class UserRestServer {
	public static void main(String[] args) throws Exception {
		// 端口
		Server server = new Server(TradeEnums.RestServerEnum.USER.getServerPort());
		// mvcHandler
		ServletContextHandler springMvcHandler = new ServletContextHandler();
		springMvcHandler.setContextPath("/" + TradeEnums.RestServerEnum.USER.getContextPath());
		// 注入监听
		XmlWebApplicationContext context = new XmlWebApplicationContext();
		context.setConfigLocation("classpath:xml/spring-web-user.xml");
		springMvcHandler.addEventListener(new ContextLoaderListener(context));
		// springMvcHandler.addServlet(new ServletHolder(new
		// DispatcherServlet(context)), "/*");
		server.setHandler(springMvcHandler);
		server.start();
		server.join();
	}

}
